package primary.linkedList;

/**
 * @Author Elephas
 * @Date 2022/1/8
 **/
public class HasCycle {
    public boolean hasCycle(ListNode head){
        if(head == null)
            return false;
        ListNode fast = head.next, slow = head;
        while (fast != null ) {
            fast = fast.next;
            if(fast != null){
                fast = fast.next;
            }
            slow = slow.next;
            if(fast == slow)
                break;
        }
        if(fast == slow )
            return true;
        else
            return false;
    }
}
